require 'optparse'

module Pushnote
  class Cli
    attr_reader :note, :configuration

    def initialize(argv)
      @note = Note.new
      parse_options
    end

    def run
      note.collect_system_info
      read_note_body
      save_note
    end

    private

    def parse_options
      OptionParser.new { |opts|
        opts.banner = "Usage: pushnote [options]"
        opts.on('-t TITLE', '--title TITLE', 'Note title') do |title|
          note.title = title
        end

        opts.on('-h HOST', '--host HOST', 'Pushnote server host') do |host|
          note.set_server_host(host)
        end
     }.parse!
    end

    def read_note_body
      note.body = STDIN.read.chomp
    end

    def save_note
      note.save
    end
  end
end
